<?php
namespace Admin\Controller;

class TemplateController extends BaseController{
	private $pay = array(1=>'货到付款',2=>'支付宝',4=>'财付通',6=>'微信支付',8=>'云支付');
	
    public function index(){
    	$Template = D('Template');
    	$object = $Template->all($this->page($Template->total()));
    	if ($object){
    		$Manager = D('Manager');
			$Ostate = D('Ostate');
	    	foreach ($object as $key=>$value){
	    		if ($value['uid']){
		    		$object2 = $Manager->one($value['uid']);
		    		$object[$key]['admin'] = $object2 ? $object2['name'] : '此管理员已被删除';
	    		}else{
	    			$object[$key]['admin'] = '不指定';
	    		}
				$object3 = $Ostate->one($value['state']);
				$object[$key]['state'] = $object3 ? '<span style="color:'.$object3['color'].';">'.$object3['name'].'</span>' : '此状态已被删除';
	    	}
    	}
    	$this->assign('All',$object);
    	$this->display();
    }
    
    public function add(){
    	if (IS_POST){
    		$Template = D('Template');
    		$object = $Template->insert();
    		if (is_numeric($object)){
    			$object>0 ? $this->success(U(CONTROLLER_NAME.'/index'),'模板添加成功！') : $this->failed('模板添加失败！');
    		}else{
    			$this->failed($object);
    		}
    	}
    	$this->admin();
    	$this->style();
    	$this->sort();
    	$this->product();
    	$this->field();
    	$this->pay();
		$this->ostate();
    	$this->verify('0,0');
    	$this->display();
    }
    
    public function update(){
		if (I('get.id')){
			$Template = D('Template');
			if (IS_POST){
				//if (in_array(I('get.id'),array(1,2,3))) $this->failed('演示站，id为1、2、3的模板无法修改！');
				$object = $Template->update();
				is_numeric($object) ? $this->success(U(CONTROLLER_NAME.'/index'),'模板修改成功！') : $this->failed($object);
			}
			$object = $Template->one();
			if (!$object) $this->failed('不存在此模板！');
			$this->admin($object['uid']);
    		$this->style($object['sid']);
    		$product = explode('|',$object['product']);
    		$this->sort($product[1]);
    		$this->product($product[0]==0 ? 0 : $product[2]);
    		$this->field($object['field']);
    		$this->pay($object['pay']);
			$this->ostate($object['state']);
    		$this->verify($object['verify']);
			$this->assign('Protype',$product[0]);
			$this->assign('Pro',$product[2]);
			$this->assign('Proselected',$product[3]);
			$this->assign('Viewtype',$product[4]);
			$this->assign('One',$object);
			$this->display();
		}else{
			$this->failed('非法操作！');
		}
    }
    
    public function code(){
		if (I('get.id')){
			$Template = D('Template');
			$object = $Template->one();
			if (!$object) $this->failed('不存在此模板！');
			$this->assign('One',$object);
			$this->display();
		}else{
			$this->failed('非法操作！');
		}
    }
    
    public function delete(){
		if (I('get.id')){
			//if (in_array(I('get.id'),array(1,2,3))) $this->failed('演示站，id为1、2、3的模板无法删除！');
			$Template = D('Template');
			if (IS_POST) $Template->remove() ? $this->success(I('post.prev'),'模板删除成功！') : $this->failed('模板删除失败！');
			if (!$Template->one()) $this->failed('不存在此模板！');
    		$this->confirm('您真的要删除这条数据么？');
    	}else{
    		$this->failed('非法操作！');
    	}
    }
    
    public function ajaxProduct(){
    	if (IS_AJAX){
	    	$Product = D('Product');
	    	echo json_encode($Product->all2(I('post.sid')));
    	}
    }
    
    public function output(){
    	if (I('get.id')){
    		$Template = D('Template');
    		$object = $Template->one();
    		if (!$object) $this->failed('不存在此模板！');
    		$dir = ROOT_PATH.'/'.C('ORDER_DIR');
    		if (is_dir($dir)){
	    		$output = '';
	    		if ($object['template'] == 0){
	    			$output = file_get_contents(T('Template/order1'));
	    			$Style = D('Style');
	    			$styleObject = $Style->one($object['sid']);
	    			$output = preg_replace('/<style type="text\/css">[\w\W]*<\/style>/U','<style type="text/css">.order{width:'.($object['send'] ? 950 : 614).'px;background:'.$styleObject['bgcolor'].';border:1px solid '.$styleObject['bordercolor'].';}.order .left{border-right:1px solid '.$styleObject['bordercolor'].';}.order .left dl dd.submit input{background:'.$styleObject['buttoncolor'].';}.order .left .buy,.order .right .send{border-bottom:1px solid '.$styleObject['bordercolor'].';}</style>',$output);
	    			$output = str_replace('<div class="right"><div class="send"></div><div class="list"><div class="list1"></div><div class="list2"></div></div></div>',$object['send'] ? '<div class="right"><div class="send"></div><div class="list"><div class="list1"></div><div class="list2"></div></div></div>' : '',$output);
	    		}elseif ($object['template'] == 1){
	    			$output = file_get_contents(T('Template/order2'));
	    		}elseif ($object['template'] == 2){
	    			$output = file_get_contents(T('Template/order3'));
	    			$Style = D('Style');
	    			$styleObject = $Style->one($object['sid']);
	    			$output = preg_replace('/<style type="text\/css">[\w\W]*<\/style>/U','<style type="text/css">.order{background:'.$styleObject['bgcolor'].';border:1px solid '.$styleObject['bordercolor'].';}.order .buy{border-bottom:1px solid '.$styleObject['bordercolor'].';}.order dl dd.submit input{background:'.$styleObject['buttoncolor'].';}</style>',$output);
	    			$output = preg_replace('/<div class="new"><\/div>/',$object['send'] ? '<div class="new"></div>' : '',$output);
	    		}
	    		
	    		$output = preg_replace('/<form method="post" action="[\w\W]*"/U','<form method="post" action="'.C('WEB_URL').'index.php'.(C('URL_MODEL') ? '/SubOrder.html' : '?c=SubOrder').'"',$output);
	    		
	    		$productHtml = '';
	    		$productTemp = explode('|',$object['product']);
	    		$Product = D('Product');
	    		if ($productTemp[0] == 0){
					if ($productTemp[4] == 0){
						$productHtml .= '<select name="pid">';
						$productObject = $Product->all3($productTemp[2]);
						if ($productObject){
							foreach ($productObject as $value){
								$productHtml.= '<option value="'.$value['id'].'"'.($value['id']==$productTemp[3] ? ' selected' : '').' style="color:'.$value['color'].';" price="'.$value['price'].'">'.$value['name'].' -- '.$value['price'].'元</option>';
							}
						}
						$productHtml .= '</select>';
					}elseif ($productTemp[4] == 1){
						$productObject = $Product->all3($productTemp[2]);
						if ($productObject){
							foreach ($productObject as $value){
								$productHtml.= '<label style="color:'.$value['color'].';"><input type="radio" name="pid" value="'.$value['id'].'"'.($value['id']==$productTemp[3] ? ' checked' : '').' price="'.$value['price'].'">'.$value['name'].' -- '.$value['price'].'元</label><br>';
							}
						}
					}
	    		}elseif ($productTemp[0] == 1){
	    			$Psort = D('Psort');
	    			$psortObject = $Psort->all2($productTemp[1]);
	    			if ($psortObject){
	    				$Product = D('Product');
						if ($productTemp[4] == 0){
							$productHtml .= '<select name="pid">';
							foreach ($psortObject as $value){
								$productHtml .= '<optgroup label="'.$value['name'].'" style="color:'.$value['color'].';">';
								$productObject = $Product->all3($productTemp[2],$value['id']);
								if ($productObject){
									foreach ($productObject as $v){
										$productHtml .= '<option value="'.$v['id'].'"'.($v['id']==$productTemp[3] ? ' selected' : '').' style="color:'.($v['color'] ? $v['color'] : '#000').';" price="'.$v['price'].'">└—'.$v['name'].' -- '.$v['price'].'元</option>';
									}
								}
								$productHtml .= '</optgroup>';
							}
							$productHtml .= '</select>';
						}elseif ($productTemp[4] == 1){
							foreach ($psortObject as $value){
								$productHtml .= '<span style="color:'.$value['color'].';">'.$value['name'].'</span><br>';
								$productObject = $Product->all3($productTemp[2],$value['id']);
								if ($productObject){
									foreach ($productObject as $v){
										$productHtml .= '<label style="color:'.$v['color'].';"><input type="radio" name="pid" value="'.$v['id'].'"'.($v['id']==$productTemp[3] ? ' checked' : '').' price="'.$v['price'].'">'.$v['name'].' -- '.$v['price'].'元</label><br>';
									}
								}
							}
						}
	    			}
	    		}
	    		
	    		$payHtml = '';
	    		if ($object['pay']){
		    		$payTemp = explode('|',$object['pay']);
		    		foreach ($this->pay as $key=>$value){
		    			if (isset($payTemp[1]) && in_array($key,explode(',',$payTemp[1]))) $payHtml .= '<label><input type="radio" name="pay" value="'.$key.'"'.($key==$payTemp[0] ? ' checked' : '').'>'.$value.'</label> ';
		    		}
	    		}

	    		$dd = "\r\n    ".'<input type="hidden" name="tid" value="'.I('get.id').'">';
	    		$dd .= "\r\n    ".'<input type="hidden" name="referrer">';
	    		$fieldTemp = explode(',',$object['field']);
	    		if ($object['template']==0 || $object['template']==1){
	    			$dd .= "\r\n    <dd>请认真填写订单信息，以便您尽快收到货物</dd>";
	    			$dd .= "\r\n    ".'<dd class="pro"><span class="protext">订购产品：</span><span class="prolist">'.$productHtml.'</span></dd>';
	    			$dd .= in_array(1,$fieldTemp) ? "\r\n    ".'<dd>订购数量：<input type="text" name="count" value="1" class="text" datatype="count" nullmsg="请填写订购数量！" errormsg="订购数量必须是数字！"></dd>' : '<input type="hidden" name="count" value="1">';
					$dd .= "\r\n    ".'<dd>总价合计：<span class="total"></span>元</dd>';
	    			if (in_array(2,$fieldTemp)) $dd .= "\r\n    ".'<dd>姓　　名：<input type="text" name="name" class="text" datatype="name" nullmsg="请填写姓名！" errormsg="姓名不得小于2位或大于20位！"></dd>';
	    			if (in_array(3,$fieldTemp)) $dd .= "\r\n    ".'<dd>联系电话：<input type="text" name="tel" class="text" datatype="tel" nullmsg="请填写联系电话！" errormsg="联系电话必须是数字和-号，且不得小于7位或大于20位！"></dd>';
	    			if (in_array(4,$fieldTemp) && in_array(5,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd>所在地区：<label><input type="radio" name="type" value="a" checked>选择填写</label> <label><input type="radio" name="type" value="b">手动填写</label></dd>';
	    				$dd .= "\r\n    ".'<dd id="aa">　　　　　<select id="province" name="province" datatype="*" nullmsg="请选择省份！"></select> <select id="city" name="city" datatype="*" nullmsg="请选择城市！"></select> <select id="county" name="county"></select></dd>';
	    				$dd .= "\r\n    ".'<dd id="bb" style="display:none;">　　　　　<input type="text" name="province2" class="text2" datatype="province2" nullmsg="请填写省份！" errormsg="省份不得小于2位或大于5位！">省<input type="text" name="city2" class="text2" datatype="city2" nullmsg="请填写城市！" errormsg="城市不得小于2位或大于15位！">市<input type="text" name="county2" class="text2">区/县</dd>';
	    			}elseif (in_array(4,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd id="aa">所在地区：<select id="province" name="province" datatype="*" nullmsg="请选择省份！"></select> <select id="city" name="city" datatype="*" nullmsg="请选择城市！"></select> <select id="county" name="county"></select></dd>';
	    			}elseif (in_array(5,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd id="bb">所在地区：<input type="text" name="province2" class="text2" datatype="province2" nullmsg="请填写省份！" errormsg="省份不得小于2位或大于5位！">省<input type="text" name="city2" class="text2" datatype="city2" nullmsg="请填写城市！" errormsg="城市不得小于2位或大于15位！">市<input type="text" name="county2" class="text2">区/县</dd>';
	    			}
	    			if (in_array(6,$fieldTemp)) $dd .= "\r\n    ".'<dd>街道地址：<input type="text" name="address" class="text" datatype="address" nullmsg="请填写街道地址！" errormsg="街道地址不得小于5位或大于200位！"></dd>';
	    			if (in_array(7,$fieldTemp)) $dd .= "\r\n    ".'<dd>邮政编码：<input type="text" name="post" maxlength="6" class="text2" datatype="post" errormsg="邮政编码必须是6位的数字！"></dd>';
	    			if (in_array(8,$fieldTemp)) $dd .= "\r\n    ".'<dd class="textarea"><span>备　　注：</span><textarea name="note" datatype="note" errormsg="备注不得大于250位！"></textarea></dd>';
	    			if (in_array(9,$fieldTemp)) $dd .= "\r\n    ".'<dd>电子邮箱：<input type="text" name="email" placeholder="选填，可接收物流信息" class="text" datatype="email" errormsg="电子邮箱格式不合法！"></dd>';
	    			$dd .= "\r\n    ".($payHtml ? '<dd>支付方式：'.$payHtml.'</dd>' : '<input type="hidden" name="pay" value="'.$payTemp[0].'">');
	    			if ($object['verify']) $dd .= "\r\n    ".'<dd class="verify"><span>验 证 码：<input type="text" name="verify" class="text2" datatype="*" nullmsg="请填写验证码！"></span> <img src="'.C('WEB_URL').'index.php?c=Public&a=verify&id='.I('get.id').'" alt="验证码" onClick="this.src=\''.C('WEB_URL').'index.php?c=Public&a=verify&id='.I('get.id').'&tm=\'+Math.random();" title="看不清？换一张"></dd>';
	    		}elseif ($object['template'] == 2){
	    			$dd .= "\r\n    ".'<dd class="center">请认真填写订单信息，以便您尽快收到货物</dd>';
	    			$dd .= "\r\n    ".'<dd class="pro"><span class="left">订购产品：</span><span class="right">'.$productHtml.'</span></dd>';
	    			$dd .= in_array(1,$fieldTemp) ? "\r\n    ".'<dd><span class="left">订购数量：</span><span class="right"><input type="text" name="count" value="1" class="text" datatype="count" nullmsg="请填写订购数量！" errormsg="订购数量必须是数字！"></span></dd>' : '<input type="hidden" name="count" value="1">';
					$dd .= "\r\n    ".'<dd><span class="left">总价合计：</span><span class="right"><span class="total"></span>元</span></dd>';
	    			if (in_array(2,$fieldTemp)) $dd .= "\r\n    ".'<dd><span class="left">姓　　名：</span><span class="right"><input type="text" name="name" class="text" datatype="name" nullmsg="请填写姓名！" errormsg="姓名不得小于2位或大于20位！"></span></dd>';
	    			if (in_array(3,$fieldTemp)) $dd .= "\r\n    ".'<dd><span class="left">联系电话：</span><span class="right"><input type="text" name="tel" class="text" datatype="tel" nullmsg="请填写联系电话！" errormsg="联系电话必须是数字和-号，且不得小于7位或大于20位！"></span></dd>';
	    			if (in_array(4,$fieldTemp) && in_array(5,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd><span class="left">所在地区：</span><span class="right"><label><input type="radio" name="type" value="a" checked>选择填写</label> <label><input type="radio" name="type" value="b">手动填写</label></span></dd>';
	    				$dd .= "\r\n    ".'<dd id="aa"><span class="left"></span><span class="right"><select id="province" name="province" datatype="*" nullmsg="请选择省份！"></select> <select id="city" name="city" datatype="*" nullmsg="请选择城市！"></select> <select id="county" name="county"></select></span></dd>';
	    				$dd .= "\r\n    ".'<dd id="bb" style="display:none;"><span class="left"></span><span class="right"><input type="text" name="province2" class="text2" datatype="province2" nullmsg="请填写省份！" errormsg="省份不得小于2位或大于5位！">省<input type="text" name="city2" class="text2" datatype="city2" nullmsg="请填写城市！" errormsg="城市不得小于2位或大于15位！">市<input type="text" name="county2" class="text2">区/县</span></dd>';
	    			}elseif (in_array(4,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd id="aa"><span class="left">所在地区：</span><span class="right"><select id="province" name="province" datatype="*" nullmsg="请选择省份！"></select> <select id="city" name="city" datatype="*" nullmsg="请选择城市！"></select> <select id="county" name="county"></select></span></dd>';
	    			}elseif (in_array(5,$fieldTemp)){
	    				$dd .= "\r\n    ".'<dd id="bb"><span class="left">所在地区：</span><span class="right"><input type="text" name="province2" class="text2" datatype="province2" nullmsg="请填写省份！" errormsg="省份不得小于2位或大于5位！">省<input type="text" name="city2" class="text2" datatype="city2" nullmsg="请填写城市！" errormsg="城市不得小于2位或大于15位！">市<input type="text" name="county2" class="text2">区/县</span></dd>';
	    			}
	    			if (in_array(6,$fieldTemp)) $dd .= "\r\n    ".'<dd><span class="left">街道地址：</span><span class="right"><input type="text" name="address" class="text" datatype="address" nullmsg="请填写街道地址！" errormsg="街道地址不得小于5位或大于200位！"></span></dd>';
	    			if (in_array(7,$fieldTemp)) $dd .= "\r\n    ".'<dd><span class="left">邮政编码：</span><span class="right"><input type="text" name="post" maxlength="6" class="text" datatype="post" errormsg="邮政编码必须是6位的数字！"></span></dd>';
	    			if (in_array(8,$fieldTemp)) $dd .= "\r\n    ".'<dd class="textarea"><span class="left">备　　注：</span><span class="right"><textarea name="note" datatype="note" errormsg="备注不得大于250位！"></textarea></span></dd>';
	    			if (in_array(9,$fieldTemp)) $dd .= "\r\n    ".'<dd><span class="left">电子邮箱：</span><span class="right"><input type="text" name="email" placeholder="选填，可接收物流信息" class="text" datatype="email" errormsg="电子邮箱格式不合法！"></span></dd>';
	    			$dd .= "\r\n    ".($payHtml ? '<dd class="pay"><span class="left">支付方式：</span><span class="right">'.$payHtml.'</span></dd>' : '<input type="hidden" name="pay" value="'.$payTemp[0].'">');
	    			if ($object['verify']){
						$dd .= "\r\n    ".'<dd><span class="left">验 证 码：</span><span class="right"><input type="text" name="verify" class="text2" datatype="*" nullmsg="请填写验证码！"></span></dd>';
						$dd .= "\r\n    ".'<dd class="verify"><span class="left"></span><span class="right"><img src="'.C('WEB_URL').'index.php?c=Public&a=verify&id='.I('get.id').'" alt="验证码" onClick="this.src=\''.C('WEB_URL').'index.php?c=Public&a=verify&id='.I('get.id').'&tm=\'+Math.random();" title="看不清？换一张"></span></dd>';
					}
	    		}
				if ($object['qq'] == 0){
					$dd .= "\r\n    ".'<dd class="info info1">请认真填写以上信息，然后点击下面的“立即提交订单”按钮以完成下单</dd>';
					$dd .= "\r\n    ".'<dd class="submit"><input type="submit" value="立即提交订单"></dd>';
				}else{
					$dd .= "\r\n    ".'<dd class="info info1" style="display:none;">请认真填写以上信息，然后点击下面的“立即提交订单”按钮以完成下单</dd>';
					$dd .= "\r\n    ".'<dd class="info info2">为防止刷单，本站需登录QQ才能下单，登录后即可看见提交按钮</dd>';
					$dd .= "\r\n    ".'<dd class="submit"><input type="submit" value="立即提交订单" style="display:none;"> <img src="'.C('WEB_URL').'Public/Home/images/qq_login.png" alt="QQ登录" onClick="window.open(\''.C('WEB_URL').'index.php?c=Public&a=qq\',\'qq\')"></dd>';
				}
	    		$output = str_replace(
	    			array(
	    				'<title>填写订单</title>',
	    				'<script type="text/javascript" src="Public',
	    				'<link rel="stylesheet" type="text/css" href="Public'
	    			),
	    			array(
	    				'<title>'.$object['name'].'</title>',
	    				'<script type="text/javascript" src="'.C('WEB_URL').'Public',
	    				'<link rel="stylesheet" type="text/css" href="'.C('WEB_URL').'Public'
	    			),
	    		$output);
	    		$output = preg_replace('/<dl class="form">[\w\W]*<\/dl>/U','<dl>'.$dd."\r\n  </dl>",$output);
				if ($object['search']){
					$output = preg_replace('/<form method="get" action="[\w\W]*"/U','<form method="get" action="'.C('WEB_URL').'index.php"',$output);
					$output = str_replace('<input type="hidden" name="tid" value="">','<input type="hidden" name="tid" value="'.I('get.id').'">',$output);
				}else{
					$output = preg_replace('/<form method="get" action="" target="_blank" class="search">[\w\W]*<\/form>/','',$output);
				}
	    		file_put_contents($dir.'/'.$object['file'],$output) ? $this->success(C('PREV_URL'),'订单页生成成功！') : $this->failed('订单页生成失败，请检查'.C('ORDER_DIR').'目录权限！');
    		}else{
    			$this->failed(C('ORDER_DIR').'目录不存在，请登录FTP或服务器手动创建！');
    		}
    	}else{
    		$this->failed('非法操作！');
    	}
    }
    
    public function selected(){
    	if (I('get.id')){
    		$Template = D('Template');
    		if (!$Template->one()) $this->failed('不存在此模板！');
    		if (!$Template->selected()) $this->failed('设置默认模板失败！');
    		$this->success(C('PREV_URL'));
    	}else{
    		$this->failed('非法操作！');
    	}
    }
    
    private function admin($n=0){
    	$html = '';
    	$Manager = D('Manager');
    	$object = $Manager->all2();
    	if ($object){
    		foreach ($object as $value){
    			$html .= '<option value="'.$value['id'].'"'.($value['id']==$n ? ' selected' : '').'>'.$value['name'].'</option>';
    		}
    	}
    	$this->assign('Admin2',$html);
    }
    
    private function style($n=0){
    	$html = '';
    	$Style = D('Style');
    	$object = $Style->all2();
    	if ($object){
    		foreach ($object as $value){
    			$html .= '<option value="'.$value['id'].'"'.($value['id']==$n ? ' selected' : '').'>'.$value['id'].'号样式</option>';
    		}
    	}
    	$this->assign('Style',$html);
    }
    
    private function sort($n=0){
    	$html = '';
    	$Psort = D('Psort');
    	$object = $Psort->all2();
    	if ($object){
    		foreach ($object as $value){
    			$html .= '<option value="'.$value['id'].'"'.($value['id']==$n ? ' selected' : '').' style="color:'.$value['color'].';">'.$value['name'].'</option>';
    		}
    	}
    	$this->assign('Sort',$html);
    }
    
    private function product($n=0){
    	$html = '';
    	$Psort = D('Psort');
    	$object = $Psort->all2();
    	if ($object){
    		$Product = D('Product');
    		foreach ($object as $value){
    			$html .= '<optgroup label="'.$value['name'].'" style="color:'.$value['color'].';" value="'.$value['id'].'">';
    			$object2 = $Product->all2($value['id']);
    			if ($object2){
    				foreach ($object2 as $v){
    					$html .= '<option value="'.$v['id'].'"'.(in_array($v['id'],explode(',',$n)) ? ' selected' : '').' style="color:'.($v['color'] ? $v['color'] : '#000').';">└—'.$v['name'].'（'.$v['price'].'元）</option>';
    				}
    			}
    			$html .= '</optgroup>';
    		}
    	}
    	$this->assign('Product',$html);
    }
    
    private function field($n=array()){
    	$html = '';
    	$Field = D('Field');
    	$selected = arrToStr($Field->all3(),'id');
    	$n = is_array($n) ? $selected : $n;
    	$object = $Field->all2();
    	if ($object){
    		foreach ($object as $value){
    			$html .= '<label'.(in_array($value['id'],explode(',',$selected)) ? ' class="red"' : '').'><input type="checkbox" name="field[]"'.(in_array($value['id'],explode(',',$n)) ? ' checked' : '').' value="'.$value['id'].'">'.$value['name'].'&nbsp;</label>';
    		}
    	}
    	$this->assign('Field',$html);
    }
    
    private function pay($n=0){
    	$html = $html2 = '';
    	$n = explode('|',$n);
    	foreach ($this->pay as $key=>$value){
    		$html .= '<label><input type="checkbox" name="pay[]" value="'.$key.'"'.(isset($n[1])==2 && in_array($key,explode(',',$n[1])) ? ' checked' : '').'>'.$value.'</label> ';
    		
    	}
    	$this->assign('Pay',$html);
    	foreach ($this->pay as $key=>$value){
    		$html2 .= '<option value="'.$key.'"'.(in_array($key,explode(',',$n[0])) ? ' selected' : '').'>'.$value.'</option>';
    	}
    	$this->assign('Pay2',$html2);
    }
    
    private function ostate($n=0){
    	$html = '';
    	$Ostate = D('Ostate');
    	$object = $Ostate->all2();
    	foreach ($object as $value){
    		$html .= '<option value="'.$value['id'].'"'.($value['id']==$n ? ' selected' : '').' style="color:'.$value['color'].';">'.$value['name'].'</option>';
    	}
    	$this->assign('Ostate',$html);
    }
    
    private function verify($n=0){
    	$html = $html2 = '';
    	$n = explode(',',$n);
    	$verify = array('关闭','开启');
    	foreach ($verify as $key=>$value){
    		$html .= '<label><input type="radio" name="verify" value="'.$key.'"'.($key==$n[0] ? ' checked' : '').'>'.$value.'</label> ';
    	}
    	$this->assign('Verify',$html);
    	$lang = array('英文验证码','中文验证码');
    	foreach ($lang as $key=>$value){
    		$html2 .= '<label><input type="radio" name="verify_lang" value="'.$key.'"'.(isset($n[1])&&$key==$n[1] ? ' checked' : '').'>'.$value.'</label> ';
    	}
    	$html2 .= '宽：<input type="text" name="verify_width" value="'.(isset($n[2]) ? $n[2] : 200).'" class="input-text text2">px ';
    	$html2 .= '高：<input type="text" name="verify_height" value="'.(isset($n[3]) ? $n[3] : 62).'" class="input-text text2">px ';
    	$html2 .= '位数：<input type="text" name="verify_length" value="'.(isset($n[4]) ? $n[4] : 4).'" class="input-text text2">位 ';
    	$html2 .= '字体大小：<input type="text" name="verify_fontsize" value="'.(isset($n[5]) ? $n[5] : 25).'" class="input-text text2">px';
    	$this->assign('Verify2',$html2);
    	$this->assign('VerifyDisplay',$n[0]==0 ? 'none' : 'block');
    }
}